import javax.swing.*;



public class fileOperator extends JFrame {
	
	public fileOperator(String op, FileHandler fL, WordList wl){
		
		JFileChooser fileOps = new JFileChooser();
		try{
		if(op.equalsIgnoreCase("load")){
			
			int accept = fileOps.showOpenDialog(this);
			pack();
			
			if(accept == JFileChooser.APPROVE_OPTION){
				
				String filename = fileOps.getSelectedFile().getName();
				fL.loadBoard(filename, wl);
				
			}
			
		}
		else if(op.equalsIgnoreCase("save")){
			
			int accept = fileOps.showSaveDialog(this);
			pack();
			
			if(accept == JFileChooser.APPROVE_OPTION){
				
				String filename = fileOps.getSelectedFile().getName();
				fL.saveWSFormat(filename);
				fL.saveHTML(filename, wl);
				fL.saveBoard(filename, wl);
				
			}
			
			
		}
		else if(op.equalsIgnoreCase("text")){
			
			int accept = fileOps.showOpenDialog(this);
			pack();
			
			if(accept == JFileChooser.APPROVE_OPTION){
				
				String filename = fileOps.getSelectedFile().getPath();
				fL.loadWordList(filename ,wl);
				
				
			}
			
			
		}
		
		}catch(Exception e){ JOptionPane.showMessageDialog(null, e.getMessage());}
		
	}
	
}
